using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.Xml;
using System.Diagnostics;
using System.Web;

namespace IWCommunity.Blogs.WebControls
{
    public class AdminLinks : XmlBasedControl
    {
        protected virtual void AddListLink(XmlElement oElement, string name, string listName)
        {
            SPList oList = Web.Lists[listName];
            oElement.SetAttribute(name, oList.DefaultViewUrl);
            oElement.SetAttribute("Create" + name, oList.Forms[PAGETYPE.PAGE_NEWFORM].ServerRelativeUrl + "?Source=" + HttpContext.Current.Request.Url.ToString());
            
        }

        protected override XmlDocument BuildDocument()
        {
            XmlDocument oDoc = new XmlDocument();
            oDoc.LoadXml("<AdminLinks/>");

            oDoc.DocumentElement.SetAttribute("Settings", Web.Url + "/_layouts/settings.aspx");

            AddListLink(oDoc.DocumentElement, "Posts", "Posts");
            AddListLink(oDoc.DocumentElement, "Categories", "Categories");
            AddListLink(oDoc.DocumentElement, "OtherBlogs", "Other Blogs");
            AddListLink(oDoc.DocumentElement, "Comments", "Comments");
            AddListLink(oDoc.DocumentElement, "Links", "Links");
            //add link to view all site content
            oDoc.DocumentElement.SetAttribute("allSiteContent", Web.Url + "/_layouts/viewlsts.aspx");

            return oDoc;
        }
    }
}
